package com.inspection.controller;

import com.inspection.entity.InspectionBranchDO;
import com.inspection.model.dto.BranchQueryDTO;
import com.inspection.model.dto.InspectionBranchDTO;
import com.inspection.service.InspectionBranchService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : chenjx
 * create at:  2020/11/8  6:59 下午
 */
@RestController
public class InspectionBranchController {

    @Autowired
    private InspectionBranchService inspectionBranchService;


    @ApiOperation("可以查询支部下的部门信息")
    @RequestMapping("/inspect/branch/query")
    public Wrapper<ItemList<InspectionBranchDO>> getInspectionBranchList(@RequestBody BranchQueryDTO query) {

        return Wrapper.ok(ItemList.buildItems(inspectionBranchService.getInspectionBranchList(query)));
    }

    @RequestMapping("/inspect/branch/page")
    public Wrapper<Page<InspectionBranchDO>> pageInspectionBranch(@RequestBody BranchQueryDTO page) {

        return Wrapper.ok(inspectionBranchService.pageInspectionBranch(page));
    }
    @SysLogAnno(operateCode =110201,operateName = "考核支部：新增")
    @RequestMapping("/inspect/branch/save")
    public Wrapper<String> addInspectionBranch(@RequestBody InspectionBranchDTO branchDTO){
        inspectionBranchService.addInspectionBranch(branchDTO);
        return Wrapper.ok("ok");
    }

    @RequestMapping("/inspect/branch/get")
    public Wrapper<InspectionBranchDO> getInspectionBranch(@RequestBody BranchQueryDTO query){
        return   Wrapper.ok(inspectionBranchService.getInspectionBranch(query));
    }

    @SysLogAnno(operateCode =110202,operateName = "考核支部：更新")
    @RequestMapping("/inspect/branch/update")
    public Wrapper<String> updateInspectionBranch(@RequestBody InspectionBranchDTO branchDTO){
        inspectionBranchService.updateInspectionBranch(branchDTO);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =110203,operateName = "考核支部：删除")
    @RequestMapping("/inspect/branch/del")
    public Wrapper<String> delInspectionBranch(@RequestBody InspectionBranchDTO branchDTO){
        inspectionBranchService.delInspectionBranch(branchDTO);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =110204,operateName = "考核支部：批量删除")
    @RequestMapping("/inspect/branch/batchDel")
    public Wrapper<String> batchDelInspectionBranch(@RequestBody InspectionBranchDTO branchDTO){
        inspectionBranchService.batchDelInspectionBranch(branchDTO);
        return Wrapper.ok("ok");
    }


}
